﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Globalization;

namespace Calhoon.MarkupParser
{
	public enum AttributeValueDelimiterType
	{
		Quote = '\'',
		DoubleQuote = '"',
		None = 0
	}

	public class AttributeValue
	{
		private AttributeValueDelimiterType mDelimiter;
		public AttributeValueDelimiterType Delimiter {
			get {
				return mDelimiter;
			}
			set {
				mDelimiter = value;
			}
		}

		private string mValue;
		public string Value {
			get {
				return mValue;
			}
			set {
				mValue = value;
			}
		}

		public AttributeValue(string value, AttributeValueDelimiterType delimiter) {
			mDelimiter = delimiter;
			mValue = value;
		}

		public AttributeValue(string value)
			: this(value, AttributeValueDelimiterType.DoubleQuote) {
		}

		public override bool Equals(object obj) {
			AttributeValue otherAtt = obj as AttributeValue;
			if (otherAtt == null) {
				return false;
			}

			return otherAtt.Value == this.Value;
		}

		public override int GetHashCode() {
			return Value.GetHashCode();
		}

		public virtual string RenderAttribute() {
			return string.Format(CultureInfo.InvariantCulture, "{0}{1}{0}", mDelimiter == AttributeValueDelimiterType.None ? string.Empty : ((char)mDelimiter).ToString(), mValue);
		}
	}
}